package ir_v3

import (
	"github.com/astaxie/beego/orm"
	"time"
)

type CameraZone struct {
	Id         int       `orm:"Column(Id)"`
	CameraId   int       `orm:"Column(CameraId)"`
	ZoneId     int       `orm:"Column(ZoneId)"`
	ZoneClass  string    `orm:"Column(ZoneClass)"`
	Enabled    int       `orm:"Column(Enabled)"`
	UpdateTime time.Time `orm:"Column(UpdateTime)"`
	UpdateUser string    `orm:"Column(UpdateUser)"`
}

func (u *CameraZone) TableName() string {
	return CameraZoneTBName()
}
func InsertCameraZone(c CameraZone) (int64, error) {
	o := orm.NewOrm()
	o.Using("default")
	return o.InsertOrUpdate(&c)
}

func SelectCameraZoneByDeviceId(deviceId string) (CameraZone, error) {
	o := orm.NewOrm()
	var cam CameraZone
	err := o.Raw("SELECT d_camerazones.* FROM d_camerazones "+
		"INNER JOIN d_cameras ON d_camerazones.CameraId=d_cameras.Id "+
		"WHERE DeviceId = ?;", deviceId).QueryRow(&cam)
	return cam, err
}
